package com.weixing.mall.provider.controller.rpc;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.dto.OrderSettleDto;
import com.weixing.mall.provider.api.model.enums.SettleStateEnum;
import com.weixing.mall.provider.model.domain.Order;
import com.weixing.mall.provider.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName OrderSettleController
 * @Description
 * @Author Small
 * @Date 2020/3/6 9:22
 * @Version 1.0
 **/
@RestController
@RequestMapping("api/order/settle")
public class OrderSettleController extends BaseController {

    @Autowired
    private IOrderService orderService;

    @PostMapping("notify")
    public Result notify(Long orderId) {
        System.out.println("接收到订单状态异步通知");
        Order order = orderService.getById(orderId);
        if (SettleStateEnum.SETTLED.getValue().intValue() == order.getSettleState().intValue()) {
            return ResultUtil.success();
        }
        System.out.println("订单状态异步通知");
        order.setSettleState(SettleStateEnum.SETTLED.getValue());
        orderService.updateById(order);
        return ResultUtil.success();

    }
}
